<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>注册</title>
  </head>
  <body>
    <p></p>
    用户名:<input type="text" /><br>
     密码:<input type="password" /> <br>
     确认密码:<input type="password"/> <br>
    昵称:<input type="text" /><br>
    <input type="button" value="注册" /><br>
    <script src="02ajax.js"></script>
    <script>
      const baseUrl = "http://localhost:8888";
       let oP = document.querySelector("p");
      let aInputs = document.querySelectorAll("input");
      aInputs[aInputs.length - 1].onclick = function () {
        //向接口传的数据
        let params = {
          username: aInputs[0].value,
          password: aInputs[1].value,
          rpassword: aInputs[2].value,
          nickname: aInputs[3].value, 
        };
        ajax({
          url: baseUrl + "/users/register",
          type: "post",
          params,
          fn(resData) {
            //console.log(resData);
            resData = JSON.parse(resData);
            if (resData.code == 0) {
              oP.innerText = "注册失败";
            }
            if (resData.code == 1) {
              location.href = "05login.html";
            }
          },
        });
      };
    </script>
  </body>
</html>
